/*
 * @Author       : wfl
 * @LastEditors: qiye
 * @description  :
 * @updateInfo   :
 * @Date         : 2023-02-28 11:45:50
 * @LastEditTime: 2024-02-04 12:29:47
 */
import { ikTree } from 'iking-utils'
import { ikHttp, textHeader } from '@g/api/request'

export const depApi = {
  getAllDeps: async (deptId?: any, excludeId?: string) => {
    return await ikHttp.post(`/server/system/dept/info/list/all${excludeId ? `?excludeId=${excludeId}` : ''}`, deptId, textHeader)
  },
  // 获取修改时父级部门列表
  getUpdateDepts: async (deptId: string) => await ikHttp.post(`/server/system/dept/info/list/all?excludeId=${deptId}`, deptId, textHeader),
  // 获取部门树型列表
  getDepTree: async () => ikTree.listToTree((await depApi.getAllDeps())?.data || []),
  // 新增部门
  addDep: async (params: any) => await ikHttp.post('/server/system/dept/add', params),
  // 修改
  updateDep: async (params: any) => await ikHttp.post('/server/system/dept/update', params),
  // 删除
  deleteDep: async (deptId: string) => await ikHttp.post('/server/system/dept/delete', deptId, textHeader),
  // 排序
  sortTree: async (params: any) => await ikHttp.post('/server/system/dept/drag', params),
  // 获取子单位
  getChildDep: async (parentId: string) => await ikHttp.post('/system/dept/sub/all/list', { parentDeptId: parentId })
}
